package cn.edu.scau.cmi.huangzhiyuan.simpleFactoryMethod;

import cn.edu.scau.cmi.huangzhiyuan.abstractFactory.domainAbstractClass.Insurance;
import cn.edu.scau.cmi.huangzhiyuan.domain.BodyInsurance;
import cn.edu.scau.cmi.huangzhiyuan.domain.CarInsurance;
import cn.edu.scau.cmi.huangzhiyuan.domain.OtherInsurance;
import cn.edu.scau.cmi.huangzhiyuan.domain.PersonInsurance;

/**
 * 简单工厂模式
 * 创建同一类型不同的保险
 */
public class SimpleFactory {
	public static Insurance createInsurance(String type) {
		Insurance insurance = null;
		
		// 生成对应保险
		switch(type) {
		case "car":
			insurance = new CarInsurance();
			break;
		case "person":
			insurance = new PersonInsurance();
			break;
		case "body":
			insurance = new BodyInsurance();
			break;
		case "other":
		default:
			insurance = new OtherInsurance();
			break;
		}
		
		// 返回保险
		return insurance;
	}
}
